package com.coin900.coin.cmd;


import com.coin900.coin.code.RespCode;
import com.value.mybatis.Pagination;
import com.value.utils.RegExpUtil;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.HashMap;

/**
 * Unibon
 * <p/>
 * Copyright (c) 2012 YouPeng ValueSoft Inc., All rights reserved.
 * <p/>
 * This software is the confidential and proprietary information of
 * ValueSoft Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with ValueSoft.com.
 * <p/>
 * Revision History
 * Date      		Programmer       Notes
 * 2014/12/22   	     stone		     Initial
 * *********************************************************************
 */
public class CmdSign implements Serializable {
    public CmdSign() {
    }

    public CmdSign(CmdSign reqSign) {
        this.cmdCode = reqSign.cmdCode;
        this.userId = reqSign.userId;
        this.clientId = reqSign.clientId;
        this.token = reqSign.token;
    }


    public CmdSign(String cmdCode) {
        this.cmdCode = cmdCode;
    }

    public CmdSign(String cmdCode, String source, String respCode) {
        this.cmdCode = cmdCode;
        this.respCode = respCode;
        this.source = source;
    }

    private boolean openTransaction = true;
    private boolean isAcross = false;
    private String token;
    /**
     * 命令code
     */
    private String cmdCode;
    /**
     * 请求code，用于一个cmd处理多种业务
     */
    private String reqCode;
    /**
     * 响应code,用于一个cmd处理多种业务
     */
    private String respCode = RespCode.SUCCESS;
    /**
     * 消息
     */
    private String msg;
    /**
     * 命令版本
     */
    private String cmdVersion;
    /**
     * 会话token
     */
    private String sessionToken;
    private Integer pageIndex;

    private String clientId;
    private String clientIp;
    private Integer clientType;
    private Long userId;
    private HashMap<String, Object> params;

    /**
     *
     */
    private String source = "{}";
    private boolean notifyOtherNode = false;

    private Long exeStartTime;
    private Long exeEndTime;
    private Long notifyStartTime;
    private Long notifyEndTime;


    private Integer pageSize;

    private Integer currentPage;
    private Integer pageCount;

    public boolean isOpenTransaction() {
        return openTransaction;
    }

    public void setOpenTransaction(boolean openTransaction) {
        this.openTransaction = openTransaction;
    }

    public boolean isAcross() {
        return isAcross;
    }

    public void setAcross(boolean across) {
        isAcross = across;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getCmdCode() {
        return cmdCode;
    }

    public void setCmdCode(String cmdCode) {
        this.cmdCode = cmdCode;
    }

    public String getReqCode() {
        return reqCode;
    }

    public void setReqCode(String reqCode) {
        this.reqCode = reqCode;
    }

    public String getRespCode() {
        return respCode;
    }

    public void setRespCode(String respCode) {
        this.respCode = respCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCmdVersion() {
        return cmdVersion;
    }

    public void setCmdVersion(String cmdVersion) {
        this.cmdVersion = cmdVersion;
    }

    public String getSessionToken() {
        return sessionToken;
    }

    public void setSessionToken(String sessionToken) {
        this.sessionToken = sessionToken;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageCount() {
        return pageCount;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getClientIp() {
        return clientIp;
    }

    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }

    public Integer getClientType() {
        return clientType;
    }

    public void setClientType(Integer clientType) {
        this.clientType = clientType;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getSource() {
        if (StringUtils.isEmpty(source)) {
            return "{}";
        }
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public boolean isNotifyOtherNode() {
        return notifyOtherNode;
    }

    public void setNotifyOtherNode(boolean notifyOtherNode) {
        this.notifyOtherNode = notifyOtherNode;
    }

    public Long getExeStartTime() {
        return exeStartTime;
    }

    public void setExeStartTime(Long exeStartTime) {
        this.exeStartTime = exeStartTime;
    }

    public Long getExeEndTime() {
        return exeEndTime;
    }

    public void setExeEndTime(Long exeEndTime) {
        this.exeEndTime = exeEndTime;
    }

    public Long getNotifyStartTime() {
        return notifyStartTime;
    }

    public void setNotifyStartTime(Long notifyStartTime) {
        this.notifyStartTime = notifyStartTime;
    }

    public Long getNotifyEndTime() {
        return notifyEndTime;
    }

    public void setNotifyEndTime(Long notifyEndTime) {
        this.notifyEndTime = notifyEndTime;
    }


    public void startExe() {
        this.exeStartTime = System.currentTimeMillis();
    }

    public void endExe() {
        this.exeEndTime = System.currentTimeMillis();
    }


    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }


    public HashMap<String, Object> getParams() {
        return params;
    }

    public void setParams(HashMap<String, Object> params) {
        this.params = params;
    }

    public Pagination buildPage() {
        Pagination page = new Pagination();
        page.setPageSize(this.pageSize == null ? 10 : pageSize);
        page.setCurrentPage(this.pageIndex == null ? 1 : pageIndex);
        page.setStart((page.getCurrentPage() - 1) * page.getPageSize());
        return page;
    }

    private Long totalCount;

    public Pagination setPageInfo(Pagination page) {
        this.pageCount = page.getPageSize();
        this.pageSize = page.getPageSize();
        this.pageIndex = page.getCurrentPage();
        this.totalCount=page.getCount();
        return page;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

    @Override
    public String toString() {
        JSONObject jsonObject = JSONObject.fromObject(this);
        return jsonObject.toString();
    }
}
